import 'package:flutter/material.dart';
import 'package:flutter_common_app/widgets/custom_list/list_indicator.dart';
import 'package:loading_more_list/loading_more_list.dart';

typedef Widget ItemBuilder<T>(BuildContext context, T item, int index);

class CustomLoadingMoreList<T> extends StatefulWidget {
  final LoadingMoreBase<T> loadingMoreBase;

  final ItemBuilder<T> itemBuilder;

  final EdgeInsetsGeometry padding;

  const CustomLoadingMoreList(
    this.itemBuilder,
    this.loadingMoreBase, {
    Key key,
    this.padding = const EdgeInsets.all(0),
  }) : super(key: key);

  @override
  _CustomLoadingMoreListState<T> createState() =>
      _CustomLoadingMoreListState<T>();
}

class _CustomLoadingMoreListState<T> extends State<CustomLoadingMoreList<T>> {
  @override
  Widget build(BuildContext context) {
    return LoadingMoreList(
      ListConfig<T>(
        itemBuilder: widget.itemBuilder,
        sourceList: widget.loadingMoreBase,
        padding: widget.padding,
        indicatorBuilder:
            (BuildContext context, IndicatorStatus indicatorStatus) {
          return ListIndicator(indicatorStatus, widget.loadingMoreBase);
        },
      ),
    );
  }
}
